package com.example.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.pojo.entity.Inventory;
import com.example.pojo.entity.Material;
import com.example.pojo.entity.Warehouse;
import com.example.service.IInventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @author wy
 * @since 2024/7/17
 */
@RestController
@RequestMapping("/inventory")
@Api(tags = "库存接口")
@Slf4j
public class InventoryController {

    @Autowired
    private IInventoryService iInventoryService;

    @PostMapping("/add")
    @ApiOperation("新增库存信息")
    public Result add(@RequestBody Inventory inventory){
        iInventoryService.add(inventory);
        return Result.success(inventory);
    }

    @PutMapping("/update")
    @ApiOperation("更新库存信息")
    public Result update(@RequestBody Inventory inventory){
        iInventoryService.updateById(inventory);
        return Result.success();
    }

    /**
     * 分页查询
     */
    @ApiOperation("分页展示库存信息列表")
    @GetMapping("/selectPage")
    public Result selectPage(Inventory inventory,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<Inventory> page = iInventoryService.selectPage(inventory, pageNum, pageSize);
        return Result.success(page);
    }
}
